<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css"
          media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css" media="all">
    <style>
        thead tr th {
            text-align: center !important;
        }

        tr td {
            text-align: center !important;
        }

    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
				<span class="layui-breadcrumb" lay-filter="breadcrumb">
	              <a href="javascript:;">鸡舍管理</a>
	              <a><cite>提鸡券</cite></a>
	            </span>
                    <div class="layui-inline" style="float:right;">
                        <c:if test="${orderCode!= null }">
                            <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="history.go(-1)">返回上一页
                            </button>
                        </c:if>
                    </div>
                </div>
                <div class="layui-card-body layui-form">
                    <%-- 查询条件设置 --%>
                    <div class="layui-container layui-form-item" style="padding-bottom: 50px">
                        <div class="layui-col-md12">
                            <div class="layui-col-md3">
                                <div class="layui-col-sm3" style="line-height: 38px">订单编号：</div>
                                <div class="layui-col-sm8">
                                    <input class="layui-input" name="orderNo" autocomplete="off" placeholder="支持模糊搜索">
                                </div>
                            </div>
                            <div class="layui-col-md3">
                                <div class="layui-col-sm3" style="line-height: 38px">用户昵称：</div>
                                <div class="layui-col-sm8">
                                    <input class="layui-input" name="nickName" autocomplete="off">
                                </div>
                            </div>
                            <div class="layui-col-md3">
                                <div class="layui-col-sm3" style="line-height: 38px">使用方式：</div>
                                <div class="layui-col-md7">
                                    <select name="useType" class="address" data-flag="1">
                                        <option value="">请选择</option>
                                        <option value="1" ${useType==0?'selected':''}>物流提鸡</option>
                                        <option value="2" ${useType==1?'selected':''}>预约自提</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-col-md3">
                                <div class="layui-col-sm3" style="line-height: 38px">券状态：</div>
                                <div class="layui-col-md7">
                                    <select name="status" class="address" data-flag="1">
                                        <option value="">请选择</option>
                                        <c:forEach items="${statusList}" var="item">
                                            <option value="${item.id}"
                                                ${detail.status==item.id?'selected="selected"':'' }>${item.name}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-col-md12">&nbsp;</div>
                            <div class="layui-col-md12">
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm4" style="line-height: 38px">鸡舍订单号：</div>
                                    <div class="layui-col-md7">
                                        <input class="layui-input" name="orderCode" autocomplete="off"
                                               value="${orderCode}">
                                    </div>
                                </div>
                                <div class="layui-col-md2">
                                    <div class="layui-col-sm3">
                                        <button class="layui-btn layui-btn" lay-submit
                                                lay-filter="LAY-app-contlist-search" type="submit">查询
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <%-- 数据展示 --%>
                    <table class="layui-table" id="table" lay-filter="table"></table>
                    <script type="text/html" id="toolbar">
                        <div class="layui-btn-container">
                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看详情</a>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'table'], function () {
        var $ = layui.$, layer = layui.layer, form = layui.form,
            element = layui.element, laydate = layui.laydate, table = layui.table;
        form.render('select');
        element.render();
        laydate.render({
            elem: '#laydate-cn',
            range: '~'
        });

        table.render({
            elem: '.layui-table',
            url: '/chickenCoupon/handleSelect',
            where: {orderCode: "${orderCode}"},
            page: true,
            toolbar: '#table-operate-tool',
            request: {
                pageName: 'current', //页码的参数名称，默认：page
                limitName: 'size' //每页数据量的参数名，默认：limit
            },
            cols: [[
                {field: 'nickName', title: '用户昵称'},
                {field: 'title', title: '提鸡券标题'},
                {field: 'source', title: '提鸡券来源'},
                // {field: 'chickenOrderNo', title: '鸡舍订单编号'},
                {field: 'orderNo', title: '提鸡券编号'},
                {
                    field: 'useTypeName', title: '使用方式',
                    templet:
                        function (d) {
                            if (d.useTypeName == "" || d.useTypeName == null) {
                                return "----"
                            } else {
                                return d.useTypeName
                            }
                        }
                },
                {
                    field: 'useTime', title: '使用时间',
                    templet:
                        function(d){
                            if(d.useTime==undefined || d.useTime=="undefined" || d.useTime==null){
                                return "----"
                            }else{
                                return layui.util.toDateString(d.useTime, 'yyyy-MM-dd HH:mm')
                            }
                        }
                },
                {
                    field: 'invalidTime', title: '过期时间',
                    templet: "<div>{{layui.util.toDateString(d.invalidTime, 'yyyy-MM-dd HH:mm')}}</div>"
                },
                {field: 'statusName', title: '提鸡券状态'},
                // {field: 'targetNickName', title: '转赠用户昵称', width: 150},
                {
                    field: 'givingTime', title: '转赠时间',
                    templet:
                        function (d) {
                            if (d.givingTime == undefined || d.givingTime == "undefined" || d.givingTime == null) {
                                return "----"
                            } else {
                                return layui.util.toDateString(d.givingTime, 'yyyy-MM-dd HH:mm')
                            }
                        }
                },
                {
                    field: 'createTime', title: '创建时间',
                    templet: "<div>{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm')}}</div>"
                },
                // {title: '操作', templet: '#toolbar'}
            ]],
            skin: "row",
            even: true,
            size: "lg"
        });

        var active = {
            detail: function (id) {
                window.location.href = '/chickenCoupon/chickenCouponDetail?id=' + id;
            },
            exportThis: function (bid, orderType, payType, orderStatus, phone, orderCode, payCode, queryTime) {
                window.location.href = encodeURI("/export/handleExportOrder?queryTime=" + queryTime + "&payCode=" + payCode + "&orderCode=" + orderCode + "&phone=" + phone + "&payType=" + payType
                    + "&payType=" + payType + "&bid=" + bid + "&orderType=" + orderType + "&orderStatus=" + orderStatus);
            }
        };

        $('.backList').on('click', function () {
            history.go(-1);
        });

        //导出事件触发
        $(".exportThis").on('click', function () {
            var exportThis = $(this).data('type');
            var bid = $('select[name="bid"]').find('option:selected').val();
            var orderType = $('select[name="orderType"]').find('option:selected').val();
            var payType = $('select[name="payType"]').find('option:selected').val();
            var orderStatus = $('select[name="orderStatus"]').find('option:selected').val();
            var phone = $('input[name="phone"]').val();
            var orderCode = $('input[name="orderCode"]').val();
            var payCode = $('input[name="payCode"]').val();
            var queryTime = $('input[name="queryTime"]').val();
            active[exportThis] && active[exportThis].call(this, bid, orderType, payType, orderStatus, phone, orderCode, payCode, queryTime);
        });

        //监听事件
        table.on('tool(table)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'detail') {// 详情
                active[layEvent] && active[layEvent].call(this, data.id);
            }
        });

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('table', {
                where: field
            });
        });

    })
</script>
</body>
</html>